/**
  * Author: Mei
  * Date: 2021-01-10 19:19
  * Description: 
  *
  */
#include "../head.h"
#include "../rapidjson/document.h"
#include "../rapidjson/writer.h"
#include "../rapidjson/stringbuffer.h"

using namespace rapidjson;

int main() {
    const char *json = "{\"hello\": \"world\",\"t\": true,\"f\": false,\"n\": null,\"i\": 123,\"pi\": 3.1416,\"a\":[1, 2, 3, 4]}";
    Document document;
    document.Parse(json);

    const Value &arr = document["a"];
    assert(arr.IsArray());
    for (SizeType i = 0; i < arr.Size(); ++i) {
        cout << arr[i].GetInt() << " ";
    }
    cout << endl;
    for (Value::ConstValueIterator it = arr.Begin(); it != arr.End(); ++it) {
        cout << it->GetInt() << " ";
    }
    cout << endl;
    for (auto &v : arr.GetArray())
        printf("%d ", v.GetInt());
    cout << endl;
    static const char *kTypeNames[] =
            {"Null", "False", "True", "Object", "Array", "String", "Number"};

    for (Value::ConstMemberIterator itr = document.MemberBegin();
         itr != document.MemberEnd(); ++itr) {
        printf("Type of member %s is %s\n",
               itr->name.GetString(), kTypeNames[itr->value.GetType()]);
    }

    return 0;
}